import os
import sys

if len(sys.argv) < 2:
    print('usage:', sys.argv[0], 'imu.txt')
    sys.exit(-1)

f = open(sys.argv[1], 'r')
lines = f.readlines()

f_csv = open('imu.csv', 'w')
f_csv.write('# timestamp, acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z, mag_x, mag_y, mag_z\n')

for line in lines:
    items = line.strip().split(' ')

    imu_data = items[:7]
    imu_data.append('0.0')
    imu_data.append('0.0')
    imu_data.append('0.0')
    imu_data[0] = '%.9f'%(float(imu_data[0])/1e3)

    line_out = ','.join(imu_data)
    f_csv.write(line_out + '\n')

print('finished')
